home *** CD-ROM | disk | FTP | other *** search
- #include <cd.h>
-
- /************************************************************************
- *
- * Function: FormatString
- *
- * Purpose: prepare return string
- *
- * Returns: nothing
- *
- * Side Effects: creates C string from input parameters
- *
- * Description: For each of the numArgs values in num[], convert the
- * value to an ascii string and concatenate.
- *
- ************************************************************************/
- void
- FormatString(str, num, numArgs)
- char str[];
- long num[];
- long numArgs;
- {
- short i;
- char numStr[31];
-
- ltoa(num[0], str);
- for (i = 1; i < numArgs; i++)
- {
- strcat(str, ","); /* add comma to separate items */
- ltoa(num[i], numStr);
- strcat(str, numStr);
- }
- c2pstr(str);
- }
-
-
- /************************************************************************
- *
- * Function: ltoa
- *
- * Purpose: convert long to ascii
- *
- * Returns: nothing
- *
- * Side Effects: fills 's' with ascii representation of a
- *
- * Description: straight out of K&R, page 60.
- *
- ************************************************************************/
- void
- ltoa(n, s)
- long n;
- char s[];
- {
- int i, sign;
-
- if ((sign = n) < 0)
- n = -n;
-
- i = 0;
-
- do {
- s[i++] = n % 10 + '0'; /* generate digits in reverse order */
- } while ((n /= 10) > 0); /* get rid of digit just generated */
-
- if (i == 1)
- s[i++] = '0'; /* add preceeding zero */
- if (sign < 0)
- s[i++] = '-';
-
- s[i] = '\0';
-
- reverse(s);
- }
- /************************************************************************
- *
- * Function: reverse
- *
- * Purpose: reverse string s in place
- *
- * Returns: nothing
- *
- * Side Effects: string 's' is reversed. The first char is last,
- * the last is first.
- *
- * Description: straight from K&R, page 59
- *
- ************************************************************************/
- void
- reverse(s)
- char s[];
- {
- int c, i, j;
-
- for (i = 0, j = strlen(s)-1; i < j; i++, j--)
- {
- c = s[i];
- s[i] = s[j];
- s[j] = c;
- }
- }
-
-
-